
//
//  RBProfileChangeGenderVC.m
//  CharmZone
//
//  Created by Lan on 2018/9/13.
//  Copyright © 2018年 SummerTea. All rights reserved.
//

#import "RBChangeGenderVC.h"
#import "RBThemeConfig.h"
#import "UIView+RBAdd.h"
#import "UIViewController+RBAdd.h"

@interface RBChangeGenderVC ()

@property(nonatomic, weak)IBOutlet UIView *manSelectView;
@property(nonatomic, weak)IBOutlet UIView *womanSelectView;

@property(nonatomic, assign) NSInteger gender;
@property(nonatomic, copy) void(^completion)(NSInteger gender);

@end

@implementation RBChangeGenderVC

#pragma mark - Private

- (void)dismiss
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (UIColor *)themeColor
{
    return [RBThemeConfig themeColor];
}

- (void)setView: (UIView *)view state: (BOOL)selected
{
    if (selected)
    {
        [view rbSetBorderWitdh:3 borderColor:[UIColor orangeColor]];
        view.backgroundColor = [self themeColor];
    }
    else
    {
        [view rbSetBorderWitdh:1 borderColor:[self themeColor]];
        view.backgroundColor = [UIColor clearColor];
    }
}

#pragma mark - Public

- (void)showFromVC:(UIViewController *)vc
            gender:(NSInteger)gender
        completion:(void (^)(NSInteger))completion
{
    [vc presentVc:self];
    self.gender = gender;
    self.completion = completion;
}

#pragma mark - Event

- (IBAction)manTapped:(id)sender
{
    self.gender = 1;
}

- (IBAction)womanTapped:(id)sender
{
    self.gender = 2;
}

- (IBAction)confirmTapped:(id)sender
{
    if (self.completion)
    {
        self.completion(self.gender);
    }
    [self dismiss];
}

- (IBAction)cancelTapped:(id)sender
{
    [self dismiss];
}

#pragma mark - Setter

- (void)setGender:(NSInteger)gender
{
    _gender = gender;
    if (gender == 1)
    {
        [self setView:self.manSelectView state:YES];
        [self setView:self.womanSelectView state:NO];
    }
    else if(gender == 2)
    {
        [self setView:self.manSelectView state:NO];
        [self setView:self.womanSelectView state:YES];
    }
    else
    {
        [self setView:self.manSelectView state:NO];
        [self setView:self.womanSelectView state:NO];
    }
}

@end
